﻿using System.Collections.Generic;
using System.Web.Mvc;
using sydfdl.TMS.BLL;
using sydfdl.TMS.Model;
using sydfdl.TMS.Tool;

namespace sydfdl.TMS.Areas.BusinessData.Controllers
{
    public class ArrivedController : Controller
    {
        //
        // GET: /BusinessData/Arrived/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult OrderDetail()
        {
            return View();
        }

        public ActionResult TruckIndex()
        {
            return View();
        }
        public ActionResult AddDamage(string TruckID)
        {
            ViewBag.TruckID = TruckID;
            return View();
        }
        public ActionResult TruckOrderDetail()
        {
            return View();
        }

        /// <summary>
        /// 按运货单签收
        /// </summary>
        public void GetOrderList()
        {
            string pageIndex = Request.Form.Get("pageIndex");
            string pageSize = Request.Form.Get("pageSize");
            string sortField = Request.Form.Get("sortField");
            string sortOrder = Request.Form.Get("sortOrder");
            string key = Request.Form.Get("key");
            string StartCity = Request.Form.Get("StartCity");
            string EndCity = Request.Form.Get("EndCity");
            string xml = JsonHelp.GetParaXML(pageIndex, pageSize, sortField, sortOrder, key);

            sydfdl.TMS.Model.T_BaseTable bTable = new BLLT_E_UploadOrder().GetOrderList(xml, StartCity, EndCity);
            string json = JsonHelp.EntitiesToString(bTable);
            Response.Write(json);
        }

        /// <summary>
        /// 按车签收
        /// </summary>
        public void GetTruckList()
        {
            string pageIndex = Request.Form.Get("pageIndex");
            string pageSize = Request.Form.Get("pageSize");
            string sortField = Request.Form.Get("sortField");
            string sortOrder = Request.Form.Get("sortOrder");
            string key = Request.Form.Get("key");
            string StartCity = Request.Form.Get("StartCity");
            string EndCity = Request.Form.Get("EndCity");
            string xml = JsonHelp.GetParaXML(pageIndex, pageSize, sortField, sortOrder, key);

            sydfdl.TMS.Model.T_BaseTable bTable = new BLLT_E_UploadOrder().GetTurckList(xml, StartCity, EndCity);
            string json = JsonHelp.EntitiesToString(bTable);
            Response.Write(json);
        }

        /// <summary>
        /// 整车签收入库
        /// </summary>
        /// <returns></returns>
        public string  SingIn()
        {
            string TruckID = Request.Form.Get("TruckID");
            string Result = new BLLT_E_UploadOrder().SingIn(TruckID);
            return Result;

        }

        public void GetGoodsDetail(string TruckID)
        {
            sydfdl.TMS.Model.T_BaseTable bTable = new BLLT_E_UploadOrder().GetGoodsDetailByTruck(TruckID);
            string json = JsonHelp.EntitiesToString(bTable);
            Response.Write(json);
        }

        public void SaveDamage()
        {
            string json = @"[]";
            IEnumerable<T_E_Damage> add = Request.Form.Get("add") == json ? null : JsonHelp.ConvertJsonToEntity<IEnumerable<T_E_Damage>>(Request.Form.Get("add"));
            IEnumerable<T_E_Damage> edit = Request.Form.Get("edit") == json ? null : JsonHelp.ConvertJsonToEntity<IEnumerable<T_E_Damage>>(Request.Form.Get("edit"));
            IEnumerable<T_E_Damage> del = Request.Form.Get("del") == json ? null : JsonHelp.ConvertJsonToEntity<IEnumerable<T_E_Damage>>(Request.Form.Get("del"));
            Response.Write(new BLLT_E_Damage().Save(add, edit, del));
        }
    }
}
